package com.wushi.lenovo.asia5b.app_widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

import com.mvp.utils.DisplayUtils;

/**
 * Created by zhangyuncai on 2019/1/8.
 * 倾斜的文字
 */
public class TiltView extends View {
    String text="";
    public TiltView(Context context) {
        super(context);
    }

    public TiltView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public TiltView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setColor(Color.WHITE);
        paint.setTextSize(DisplayUtils.dip2px(getContext(), 16));
        paint.setStyle(Paint.Style.FILL);
        paint.setStrokeWidth(3f);
        int width = getWidth();
        int height = getHeight();
        float measureTextWidth = paint.measureText(text);
        canvas.rotate(-15f, width / 2, height / 2);
        canvas.drawText(text, width / 2 - measureTextWidth / 2, height / 2, paint);
    }

    public void setText(String text) {
        this.text = text;
        invalidate();
    }
}
